

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <script src="../js/vue.js"></script>
</head>

<body>
  <div id="root">
    <h2>学校名称：{{name}}</h2>
    <h2>学校地址：{{address}}</h2>
  </div>
  <script>
    Vue.config.productionTip = false

    let data = {
      name: 'ccc',
      address: 'ch'
    }

    // 创建一个监视的实例对象，用于监视data中属性的变化
    const obs = new Observer(data)

    function Observer(obj) {
      // 汇总对象中所有的属性形成一个数组
      const keys = Object.keys(obj)
      // 遍历
      keys.forEach((k) => {
        Object.defineProperty(this, k, {
          get() {
            return obj[k]
          },
          set(val) {
            obj[k] = val
          }
        })
      })
    }

  </script>
</body>

</html>